import { State } from ".";
import { USER_LOGIN_REQ_MODEL } from "../../../apis/user_model";

/**
 * 用户角色类型
 * Admin 管理员
 * User 普通用户
 * Tourist 游客
 */
export type UserRoleType = "Admin" | "User" | "Tourist" | null



/**
 * Mutations 操作类型
 * SET_USER_TOKEN 设置token
 */
export enum UserMutationTypes {
  SET_USER_TOKEN = 'SET_USER_TOKEN',
  SET_USER_ROLE = 'SET_USER_ROLE',
}

export type Mutations<S = State> = {
  [UserMutationTypes.SET_USER_ROLE](state: S, payload: UserRoleType): void;
  [UserMutationTypes.SET_USER_TOKEN](state: S, payload: string): void;
};

/**
 * Action 操作类型
 * USER_LOGIN 用户登录
 */
export enum UserActionTypes {
  USER_LOGIN = 'USER_LOGIN',
}
export type AugmentedActionContext = {
  /** 
   * keyof Mutations
   * 类型只能是 Mutations中的其中一项
   * @param key 
   * @param payload 
   */
  commit<K extends keyof Mutations>(
    key: K,
    payload: Parameters<Mutations[K]>[1],
  ): ReturnType<Mutations[K]>;
}

export type Actions = {
  [UserActionTypes.USER_LOGIN](context: AugmentedActionContext, params: USER_LOGIN_REQ_MODEL): void
};